package com.kassadin.server;

import com.kassadin.common.exception.SoaException;
import com.sun.corba.se.internal.CosNaming.BootstrapServer;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.oio.OioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * ClassName: ServerBootStrapFactory
 * Description:
 *
 * @author kang.wang03
 *         Date 16/3/15
 */
public class ServerBootStrapFactory {
    public static ServerBootstrap createServerBootstrap(int bossMaxThread, int workerMaxThread) {
        ServerBootstrap bootstrap = null;
        switch (Contants.mode) {
            case "oio":
                OioEventLoopGroup bossOioGroup = new OioEventLoopGroup(bossMaxThread);
                OioEventLoopGroup workerOioGroup = new OioEventLoopGroup(bossMaxThread);
                bootstrap = new ServerBootstrap().group(bossOioGroup, workerOioGroup).channel(NioServerSocketChannel.class);
                break;
            case "nio":
                NioEventLoopGroup bossGroup = new NioEventLoopGroup(bossMaxThread);
                NioEventLoopGroup workerGroup = new NioEventLoopGroup(workerMaxThread);
                bootstrap = new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class);
                break;
            case "epoll":
                EpollEventLoopGroup bossEpollGroup = new EpollEventLoopGroup(bossMaxThread);
                EpollEventLoopGroup workerEpollGroup = new EpollEventLoopGroup(workerMaxThread);
                bootstrap = new ServerBootstrap().group(bossEpollGroup, workerEpollGroup).channel(EpollServerSocketChannel.class);
                break;
            default:
                throw new SoaException("soa mode is error");
        }
        return bootstrap;
    }
}
